{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "现基于keras搭建DNN神经网络，并基于训练集对模型进行训练"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import keras\n",
    "import pickle\n",
    "\n",
    "with open('data/train_x.pkl', 'rb') as f:\n",
    "    train_x = pickle.load(f)\n",
    "    \n",
    "with open('data/train_y.pkl', 'rb') as f:\n",
    "    train_y = pickle.load(f)\n",
    "\n",
    "init = keras.initializers.glorot_uniform(seed=1)\n",
    "simple_adam = keras.optimizers.Adam()\n",
    "model = keras.models.Sequential()\n",
    "model.add(keras.layers.Dense(units=512, input_dim=1434, kernel_initializer=init, activation='relu'))\n",
    "model.add(keras.layers.Dense(units=256, kernel_initializer=init, activation='relu'))\n",
    "model.add(keras.layers.Dense(units=128, kernel_initializer=init, activation='relu'))\n",
    "model.add(keras.layers.Dropout(0.1))\n",
    "model.add(keras.layers.Dense(units=96, kernel_initializer=init, activation='tanh'))\n",
    "model.compile(loss='mse', optimizer=simple_adam, metrics=['accuracy'])\n",
    "model.fit(train_x, train_y, epochs=1000, batch_size=7, shuffle=True, verbose=True)\n",
    "\n",
    "with open('data/model.pkl', 'wb') as f:\n",
    "    pickle.dump(model, f)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
